﻿
/*=========================================
* Author: 欧石楠
* Description: SpringGUI.LineChartGraph example.
==========================================*/

using System.Collections.Generic;
using SpringGUI;
using UnityEngine;

namespace BridgeShips {
    public class UILineChartGraph : MonoBehaviour {
        public class ChartValue {
            public float xValue { get; set; }
            public float yValue { get; set; }

            public ChartValue( float x, float y ) {
                xValue = x;
                yValue = y;
            }
        }



        public List<ChartValue> m_cvData = new List<ChartValue>();

        public LineChart LineChart  = null;

        public void UpdateBuf(LinkedList<Vector3> list) {
            if (LineChart == null)
                return;

            if (m_cvData != null && list.Count > 1) {
                LinkedListNode<Vector3> current = list.First;
                int index = m_cvData.Count;
                while (current != null) {
                    ChartValue cv = new ChartValue( current.Value.x, current.Value.y );
                    m_cvData.Insert( index, cv );
                    index++;
                    current = current.Next;
                }
            }
            LineChart.Inject<ChartValue>( m_cvData );
            LineChart.Refresh();
        }

        public void Awake() {
            
           
        }
        /// <summary>
        /// 添加折线图
        /// </summary>
        public void AddList() {
            var defultData = new List<ChartValue>()
            {
                new ChartValue(0.0f,0.1f),
                new ChartValue(0.1f,0.2f),
                new ChartValue(0.2f,0.3f),
                new ChartValue(0.3f,0.4f),
                new ChartValue(0.4f,0.5f),
                new ChartValue(0.5f,0.1f),
                new ChartValue(0.6f,0.2f),
                new ChartValue(0.7f,0.3f),
                new ChartValue(0.8f,0.4f),
                new ChartValue(0.9f,0.5f),
                new ChartValue(1f,0.5f),

            };
            if (LineChart == null)
                return;
            LineChart.Inject<ChartValue>( defultData );
            ShowLineChart();
        }

        public void ShowLineChart() {

            if(LineChart != null) {
                LineChart.ShowUnit();
            }
        }

        public void OnGUI() {
            //if (GUILayout.Button( "Reset" )) {
            //    LineChart.Refresh();
            //}
            //GUILayout.Label( "Static Data" );
            //if (GUILayout.Button( "Mode1" )) {
            //    LineChart.lineChartType = LineChart.LineChartType.LineChart1;
            //    LineChart.Refresh();
            //}
            //if (GUILayout.Button( "Mode2" )) {
            //    LineChart.lineChartType = LineChart.LineChartType.LineChart2;
            //    LineChart.Refresh();
            //}
            //if (GUILayout.Button( "Mode3" )) {
            //    LineChart.lineChartType = LineChart.LineChartType.LineChart3;
            //    LineChart.Refresh();
            //}
            //if (GUILayout.Button( "Delete one line " )) {
            //    LineChart.RemoveLine( 1 );
            //}
            //GUILayout.Label( "Dynamic Data" );
            //GUILayout.Space( 5 );
            //if (GUILayout.Button( "Replace all data" )) {
            //    LineChart.Replace( 1, m_cvData );


            //}
            //GUILayout.Space( 5 );
            //if (GUILayout.Button( " Dynamic stream data " )) {
            //    LineChart.InjectVertexStream( 1, m_cvData );
            //}
        }
    }
}